package top.chmin.project.cloud.sys.sequence.info;

import java.util.Map;

import top.chmin.project.cloud.sys.dict.data.DictDataCondition;
import top.chmin.project.cloud.sys.dict.data.DictData;

import java.util.List;

import top.chmin.project.cloud.common.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import cn.hutool.core.bean.BeanUtil;


/**
 * chmin
 * 2024-01-29 16:24:09
 * cloud-code
 */
@Service
@Transactional
public class SequenceInfoService {

    @Resource
    SequenceInfoPlugin plugin;

    public int save(SequenceInfoSaveRest.P p) {
        plugin.checkSave(p);
        SequenceInfo sequenceInfo = BeanUtil.toBean(p, SequenceInfo.class);
        plugin.beforeSave(sequenceInfo);
        int result = sequenceInfo.forInsert().execute();
        plugin.afterSave(p, sequenceInfo, result);
        return result;
    }

    public SequenceInfoSelectRest.R select(SequenceInfoSelectRest.P p) {
        plugin.checkSelect(p);
        SequenceInfoCondition c = SequenceInfoCondition.forSelect().id().eq(p.getId());
        plugin.beforeSelect(p, c);
        SequenceInfoSelectRest.R r = c.selectFirst(SequenceInfoSelectRest.R.class);
        plugin.afterSelect(p, r);
        return r;
    }

    public int update(SequenceInfoUpdateRest.P p) {
        plugin.checkUpdate(p);
        SequenceInfo sequenceInfo = BeanUtil.toBean(p, SequenceInfo.class);
        plugin.beforeUpdate(sequenceInfo);
        int result = sequenceInfo.forUpdate().id().eq().execute();
        plugin.afterUpdate(p, sequenceInfo, result);
        return result;
    }

    public int delete(SequenceInfoDeleteRest.P p) {
        plugin.checkDelete(p);
        SequenceInfo sequenceInfo = BeanUtil.toBean(p, SequenceInfo.class);
        plugin.beforeDelete(sequenceInfo);
        int result = sequenceInfo.forDelete().id().eq().execute();
        plugin.afterDelete(p, sequenceInfo, result);
        return result;
    }

    public Page<SequenceInfoPageRest.R> page(SequenceInfoPageRest.P p) {
        plugin.checkPage(p);
        SequenceInfoCondition c = SequenceInfoCondition.forSelect();
        c = p.isDesc() ? c.id().desc() : c.id().asc();
        plugin.beforePage(p, c);
        Page<SequenceInfoPageRest.R> r = c.selectPage(SequenceInfoPageRest.R.class);
        /* append $serviceRelateAppender$ */
        /*###########auto#start###########*/
        /*###########auto##end############*/
        /* append $serviceDictAppender$ */
        plugin.afterPage(p, r);
        return r;
    }
    /* append $serviceSelectOptionMethodAppender$ */
}
